package com.example.canalclientsync.es.document;

import com.example.canalclientsync.canal.po.FileEditUser;
import com.example.canalclientsync.canal.po.Project;
import com.example.canalclientsync.canal.po.Dir;
import com.example.canalclientsync.es.enums.EsModelClassificationEnum;
import com.example.canalclientsync.es.enums.EsPersonalFileOriginTypeEnum;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;

import java.util.Date;
import java.util.List;



/**
 * @author chen.cr
 * @since 2023/9/14
 */
@Data
@Document(indexName = EsModel._INDEX_)
public class EsModel {
    public static final String _INDEX_ = "#{@SEARCH_INDEX}";
    public static final IndexCoordinates INDEX = IndexCoordinates.of(_INDEX_);


    @Id
    @Field
    private Long id;

    /**
     * 主分类，0：个人文件，1：部门文件，2：项目文件，4：回收站，9：其它（附件、转发、关联）
     * @see EsModelClassificationEnum
     */
    @Field(type = FieldType.Keyword, name = "classification")
    private Integer classification;

    /**
     * 类型，0：文件夹，1：模型，2：图纸，9：其它
     * @see com.newdim.essearchinf.enums.EsModelKindEnum
     */
    @Field(type = FieldType.Keyword, name = "kind")
    private Integer kind;

    /**
     * 模型/文件夹 名称
     */
    @Field(type = FieldType.Text, name = "name", analyzer = "ik_max_word", searchAnalyzer = "ik_max_word", fielddata = true)
    private String name;

    /**
     * 文件相关属性
     */
    @Field(type = FieldType.Long, name = "modelId")
    private Long modelId;
    @Field(type = FieldType.Long, name = "masterId")
    private Long masterId;
    @Field(type = FieldType.Text, name = "version")
    private String version;
    @Field(type = FieldType.Long, name = "size")
    private Long size;
    @Field(type = FieldType.Text, name = "detaiImg")
    private String detaiImg;
    @Field(type = FieldType.Text, name = "screenshot")
    private String screenshot;
    @Field(type = FieldType.Text, name = "ossUrl")
    private String ossUrl;
    /**
     * 是否为最新版本
     */
    @Field(type = FieldType.Boolean, name = "latest")
    private Boolean latest;

    /**
     * 是否是文件夹， 需要根据该字段进行排序
     */
    @Field(type = FieldType.Boolean, name = "isFolder")
    private Boolean isFolder;

    /**
     * 后缀
     */
    @Field(type = FieldType.Keyword, name = "extension")
    private String extension;


//    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    // @Field(type = FieldType.Date, format = DateFormat.basic_date_time)
    @Field(type = FieldType.Date)
    private Date createTime;
//    @Field(type = FieldType.Date, format = {}, pattern = "yyyy-MM-dd HH:mm:ss")
    // @Field(type = FieldType.Date, format = DateFormat.basic_date_time)
    @Field(type = FieldType.Date)
    private Date lastUpdateTime;

    @Field(type = FieldType.Keyword, name = "createUserId")
    private Integer createUserId;
    @Field(type = FieldType.Keyword, name = "lastUpdateUserId")
    private Integer lastUpdateUserId;

    /**
     * 项目空间文件——所属项目
     */
    @Field(type = FieldType.Object, name = "belongedProject")
    private Project belongedProject;
    /**
     * 所属目录
     */
    @Field(type = FieldType.Object, name = "belongedCatalog")
    private Dir belongedCatalog;
    /**
     * 是否为项目附件
     */
    @Field(type = FieldType.Boolean, name = "asAttachment")
    private Boolean asAttachment;

    /**
     * 部门空间文件——所属部门ID
     * 查询时，先查询用户有权限访问的部门有哪些，然后根据这些部门id进行过滤
     */
    @Field(type = FieldType.Keyword, name = "belongedDepartmentId")
    private Integer belongedDepartmentId;

    /**
     * 个人空间文件——所属用户ID
     */
    @Field(type = FieldType.Keyword, name = "belongedUserId")
    private Integer belongedUserId;


    /**
     * 文件所有者
     */
    @Field(type = FieldType.Keyword)
    private Integer ownerUserId;
    /**
     * 文件修改人（编辑者）
     */
    @Field(type = FieldType.Nested)
    private List<FileEditUser> editorUserList;

    /**
     * 个人空间文件来源
     * @see EsPersonalFileOriginTypeEnum
     */
    @Field(type = FieldType.Keyword)
    private Integer originType;

    /**
     * 所在文件夹
     */
    @Field(type = FieldType.Object)
    private Dir parentDir;


    /**
     * 企业租户ID
     */
    @Field(type = FieldType.Keyword, name = "tenantId")
    private String tenantId;

}
